package com.insurance.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.insurance.common.utils.PageUtils;
import com.insurance.common.utils.Query;
import com.insurance.dao.ProposalCustomerDao;
import com.insurance.entity.ProposalCustomerEntity;
import com.insurance.enums.ProposalCustomerTypeEnum;
import com.insurance.enums.ProposalPersonTypeEnum;
import com.insurance.service.ProposalCustomerService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("proposalCustomerService")
public class ProposalCustomerServiceImpl extends ServiceImpl<ProposalCustomerDao, ProposalCustomerEntity> implements ProposalCustomerService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ProposalCustomerEntity> page = this.page(
                new Query<ProposalCustomerEntity>().getPage(params),
                new QueryWrapper<ProposalCustomerEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 通过投保单主键查询
     *
     * @param proposalId 投保单主键
     * @return
     */
    @Override
    public List<ProposalCustomerEntity> findByProposalId(String proposalId){
        QueryWrapper<ProposalCustomerEntity> queryWrapper = new QueryWrapper<ProposalCustomerEntity>();
        queryWrapper.eq("proposal_id", proposalId);
        return this.list(queryWrapper);
    }


    /**
     * 通过投保单主键查询投保人对象
     *
     * @param proposalId 投保单主键
     * @return
     */
    @Override
    public ProposalCustomerEntity findApplicationCustomer(String proposalId){
        QueryWrapper<ProposalCustomerEntity> queryWrapper = new QueryWrapper<ProposalCustomerEntity>();
        queryWrapper.eq("proposal_id", proposalId);
        queryWrapper.eq("customer_type", ProposalCustomerTypeEnum.INSURE.getCode());
        return this.getOne(queryWrapper);
    }

    /**
     * 通过投保单主键查询被保人对象
     *
     * @param proposalId 投保单主键
     * @return
     */
    @Override
    public ProposalCustomerEntity findInsuredCustomer(String proposalId){
        QueryWrapper<ProposalCustomerEntity> queryWrapper = new QueryWrapper<ProposalCustomerEntity>();
        queryWrapper.eq("proposal_id", proposalId);
        queryWrapper.eq("customer_type", ProposalCustomerTypeEnum.BEINSURE.getCode());
        return this.getOne(queryWrapper);
    }

}